From d154132afec5a6c4d58da62d901c4e426d4b6ccb Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Tue, 20 Sep 2022 12:03:33 -0600 Subject: [PATCH] coretool fixes and enhancements (#921) * get coretool to work on macos under qmake. * enhance coretool. 1. don't use stderr for coretool output. This avoids comingling of real error messages with the coretool output. 2. disable the similartext heuristic with coretool. This heuristic, which is enabled by default, was resulting in occasional mistranslations. --- gui/coretool/coretool.cc | 28 ++++++++++++++++++++++++++-- gui/coretool/coretool.pro | 10 ++++++++-- gui/formatload.cc | 6 +++++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/gui/coretool/coretool.cc b/gui/coretool/coretool.cc index fe562e3fa..3121cf186 100644 --- a/gui/coretool/coretool.cc +++ b/gui/coretool/coretool.cc @@ -1,12 +1,36 @@ -#include #include +#include +#include +#include #include "format.h" #include "formatload.h" +QTextStream* generate_output_stream; + int main(int argc, char** argv) { QApplication app(argc, argv); + QStringList qargs = QApplication::arguments(); + QList formatList; - return FormatLoad().getFormats(formatList) ? 0 : 1; + + if (qargs.size() != 2) { + qFatal("Usage: %s output_file_name", qPrintable(qargs.at(0))); + } + + QFile generate_output_file(qargs.at(1)); + bool status = generate_output_file.open(QIODevice::WriteOnly); + if (!status) { + qFatal("Could not open %s for write!", qPrintable(qargs.at(1))); + } + generate_output_stream = new QTextStream(&generate_output_file); + + bool fmtstatus = FormatLoad().getFormats(formatList); + + generate_output_stream->flush(); + generate_output_file.close(); + delete generate_output_stream; + + return fmtstatus ? 0 : 1; } diff --git a/gui/coretool/coretool.pro b/gui/coretool/coretool.pro index abcc7bdc4..459fe38ee 100644 --- a/gui/coretool/coretool.pro +++ b/gui/coretool/coretool.pro @@ -4,6 +4,7 @@ # these strings. # CONFIG += console +CONFIG -= app_bundle QT -= gui QT += core \ @@ -29,13 +30,18 @@ core_strings.target = core_strings.h core_strings.depends = $(TARGET) core_strings.depends += ../../gpsbabel core_strings.commands = $(COPY_FILE) ../../gpsbabel $(DESTDIR)gpsbabel && -core_strings.commands += ./$(TARGET) 2>core_strings.h; +core_strings.commands += ./$(TARGET) core_strings.h; QMAKE_EXTRA_TARGETS += core_strings QMAKE_DISTCLEAN += $(DESTDIR)gpsbabel +# The line numbers are almost meaningless the way we generate corestrings.h, and we force everything to the same context. +# With line numbers and the similartext heuristic enabled translations can be copied from an old message to a new message, +# and marked as unfinished. The threshold for similar is low. +# These will be used by the application, even though they really need to be checked. +# Disable the similartext heuristic to avoid these mistranslations. qtPrepareTool(LUPDATE, lupdate) update.depends = core_strings.h -update.commands = $$LUPDATE -locations absolute core.pro +update.commands = $$LUPDATE -disable-heuristic similartext core.pro QMAKE_EXTRA_TARGETS += update qtPrepareTool(LRELEASE, lrelease) diff --git a/gui/formatload.cc b/gui/formatload.cc index 7f414846b..a0af91be6 100644 --- a/gui/formatload.cc +++ b/gui/formatload.cc @@ -40,11 +40,15 @@ #include "appname.h" // for appName +#ifdef GENERATE_CORE_STRINGS +extern QTextStream* generate_output_stream; +#endif + //------------------------------------------------------------------------ static QString xlt(const QString& f) { #ifdef GENERATE_CORE_STRINGS - qInfo().nospace() << "QT_TRANSLATE_NOOP(\"core\"," << f << ")"; + *generate_output_stream << "QT_TRANSLATE_NOOP(\"core\",\"" << f << "\")" << Qt::endl; #endif return QCoreApplication::translate("core", f.toUtf8().constData()); } -- 2.30.2